package base.flowGallery {
	import flash.display.Sprite;
	
	public class ListItems extends Sprite {
		
		private var _isLoop: Boolean;
		private var _countDisplayed: uint;
		
		public function ListItems(): void {
			
		}
		
		private function initItems():void {
			if (_isLoop) 
			
			var num:int = Math.floor(1 / DIFF);
			var n:int = NUM;
			while (n < countDisplayed) {
				n += NUM;
			}
			var j:int = 0;

			for (var i:int = 0; i < n; i++) {
				
				
				_items[i] = new Leaf(_data[i%NUM].projects[0])
				_items[i].y = 300
				_items[i].t = 0.5 + DIFF * i - (n - 1) * DIFF / 2//1-DIFF*i-3
				_items[i].addEventListener(Event.SELECT,itemSelected)
				_items[i].id = i%NUM
				
				
				j++
				
				if ((i % NUM == 0 && i>0) || NUM ==1) {
					 j=0	
				}
				
				
				
				if(i>0){
					_items[i - 1].n = _items[i]
					_items[i].p = _items[i - 1]
				}
			}
			
			
			
			_items[0].p = _items[_items.length-1]
			_items[_items.length - 1].n = _items[0]
			
			_curr = _items[0]
			_curr.t = AIM
			_curr.selected = true
			_speed = 1
			
			_cont.addChild(_curr)
			update()
			
			//select(_curr)
			
			_cont.y = -50
			
			addChild(_cont)
			
			show()
		}
		
		protected function show(): void {
			for (var i:int = 0; i < _cont.numChildren; i++) 
			{
				var _child:Leaf = _cont.getChildAt(i) as Leaf
				if (i) {
					TweenMax.from(_child,0.4,{rotation:-90,delay:0.4})
				}else {
					TweenMax.from(_child,0.4,{rotation:-90,onComplete:initEvents,delay:0.4})
				}
			}
			TweenMax.from(this,0.4,{y:1000,ease:Quad.easeOut})
		}
		
		
		public function hideAndClear():void {
			for (var i:int = 0; i < _cont.numChildren; i++) 
			{
				var _child:Leaf = _cont.getChildAt(i) as Leaf
				if (i) {
					TweenMax.to(_child,0.5,{rotation:-90,delay:0.4})
				}else {
					TweenMax.to(_child,0.5,{rotation:-90,delay:0.4})
				}
			}
			TweenMax.to(this,0.6,{y:1000,ease:Back.easeIn,delay:0.4,onComplete:destroy})
		}
		
		public function destroy():void {
			dispatchEvent(new PagesEvent(PagesEvent.ON_CLEAR))
		}

		
	}

}